using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Threading;

using PFDB.IntelisenceLib;

namespace PFDB
{
	/// <summary>
	/// Main Form
	/// </summary>
    public partial class MainForm : Form
    {
        string username = String.Empty;
        string password = String.Empty;
        string server = String.Empty;
        bool loged = false;
		Intelisence intel = null;
		string SpPath = "C:/All_SP/";
        //MySqlIntelisence my = new MySqlIntelisence();

		/// <summary>
		/// Initializes a new instance of the <see cref="Form1"/> class.
		/// </summary>
		public MainForm()
        {
			intel = new Intelisence("mysql");
            InitializeComponent();
        }
		/// <summary>
		/// Handles the Load event of the Form1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            ClearForm();
            rtbMainEditor.BackColor = Color.Black;
            rtbMainEditor.ForeColor = Color.Cyan;
            btnGetTables.Enabled = false;
            button4.Enabled = false;
            panel1.Enabled = false;
			
            //intel.addToFile();
            //addKeyWords("mysql");
        }
		/// <summary>
		/// Handles the SelectedIndexChanged event of the comboBox1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ClearForm();
            panel2.Enabled = true;
        }
		/// <summary>
		/// Handles the Click event of the button1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ArrayList tables = AppLib.MYSQLSET.DBTablesManage.GetTables((string)cmbDatabases.SelectedItem, username, password, server);
                lbTables.Items.Clear();
                foreach (object key in tables)
                {
                    lbTables.Items.Add((string)key);
                }
            } catch (Exception ex)
            {
                laStatus.Text = "Not Loged";
            }
        }
		/// <summary>
		/// Sets the env.
		/// </summary>
		/// <param name="env">The env.</param>
        public void setEnv(string env)
        {
			//Notice : Not needed
            if(env.Equals("blue"))
            {
                //richTextBox1.BackColor = Color.DarkBlue;
                //richTextBox1.ForeColor = Color.Yellow;
            }
            if(env.Equals("black"))
            {
                //richTextBox1.BackColor = Color.Black;
                //richTextBox1.ForeColor = Color.Cyan;
            }
        }
		/// <summary>
		/// Handles the Click event of the button2 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button2_Click(object sender, EventArgs e)
        {
            setEnv("black");
            rtbMainEditor.Clear();
            GenerateSelected();
        }
		/// <summary>
		/// Handles the Click event of the button3 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button3_Click(object sender, EventArgs e)
        {
            rtbMainEditor.Clear();
            setEnv("black");
            GenerateAllSP();
            //richTextBox1.ProcessAllLines();
        }
		/// <summary>
		/// Handles the DoubleClick event of the listBox1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            rtbMainEditor.Clear();
            setEnv("black");
            GenerateSelected();
			rtbMainEditor.ProcessAllLines();
        }
		/// <summary>
		/// Handles the SelectedIndexChanged event of the listBox1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            panel1.Enabled = true;
            btnCreateAllProcedures.Enabled = true;
        }
		/// <summary>
		/// Handles the Click event of the button8 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button8_Click(object sender, EventArgs e)
        {
            setEnv("black");
            GenerateSelected();
        }
		/// <summary>
		/// Handles the MouseDown event of the listBox1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        private void listBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button.Equals(MouseButtons.Right))
            {
                setEnv("black");
                GenerateSelected();
            }
        }
		/// <summary>
		/// Handles the Click event of the button7 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button7_Click(object sender, EventArgs e)
        {
            setEnv("blue");
            rtbMainEditor.Clear();
            RetrieveAllSP();
        }
		/// <summary>
		/// Handles the MouseDoubleClick event of the listBox2 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        private void listBox2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            setEnv("blue");
            rtbMainEditor.Clear();
            RetrieveSelected();
			rtbMainEditor.ProcessAllLines();
        }
		/// <summary>
		/// Handles the MouseDown event of the listBox2 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        private void listBox2_MouseDown(object sender, MouseEventArgs e)
        {
            if(e.Button.Equals(MouseButtons.Right))
            {
                setEnv("blue");
                RetrieveSelected();
            }
        }
		/// <summary>
		/// Handles the SelectedIndexChanged event of the listBox2 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            tbGetAllProcedures.Enabled = true;
        }
		/// <summary>
		/// Handles the Click event of the button4 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                lbStoredProcedures.Items.Clear();
                ArrayList SP = AppLib.MYSQLSET.DBTablesManage.GetSP((string)cmbDatabases.SelectedItem, username, password, server);
                foreach (object key in SP)
                {
                    lbStoredProcedures.Items.Add((string)key);
                }
            } catch (Exception)
            {
                laStatus.Text = "WHAT??????????";
            }
        }
		/// <summary>
		/// Clears the form.
		/// </summary>
        private void ClearForm()
        {
            try
            {
                lbTables.Items.Clear();
                lbStoredProcedures.Items.Clear();
                rtbMainEditor.Clear();
                btnCreateAllProcedures.Enabled = false;
                tbGetAllProcedures.Enabled = false;
                panel1.Enabled = false;
            } catch (Exception)
            {
                laStatus.Text = "WHAT??????????";
            }
        }
		/// <summary>
		/// Handles the Click event of the button5 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button5_Click(object sender, EventArgs e)
        {
            username = tbUserName.Text;
            password = tbPassword.Text;
            server = tbServer.Text;
            MySql.Data.MySqlClient.MySqlConnection test = AppLib.MYSQLSET.DBConnect.conn("mysql", username, password, server);
            try
            {
                test.Open();
                test.Close();
                loged = true;
            } catch
            {
                loged = false;
            }


            if (loged)
            {
                foreach (object key in AppLib.MYSQLSET.DBTablesManage.GetDatabases(username, password, server))
                {
                    cmbDatabases.Items.Add((string)key);
                }
                ClearForm();
                btnGetTables.Enabled = true;
                button4.Enabled = true;
                laStatus.Text = "Do your Job";
                laStatus.BackColor = Color.Blue;
            }
            else
            {
                ClearForm();
                btnGetTables.Enabled = false;
                button4.Enabled = false;
                laStatus.Text = "Not Loged";
                laStatus.BackColor = Color.Red;
            }
        }
		/// <summary>
		/// Handles the Click event of the button6 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button6_Click(object sender, EventArgs e)
        {
            //saveFileDialog1.ShowDialog();
            Stream myStream;
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.DefaultExt = ".sql";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    rtbMainEditor.SaveFile(myStream, RichTextBoxStreamType.PlainText);
                }
                myStream.Close();
            }
        }
		/// <summary>
		/// Generates all SP.
		/// </summary>
        private void GenerateAllSP(){
            try
            {
                AppLib.MYSQLSET.DBTablesManage test = new PFDB.AppLib.MYSQLSET.DBTablesManage((string)cmbDatabases.SelectedItem, username, password, server);
                AppLib.MySQLSP newSP = new PFDB.AppLib.MySQLSP();
                for (int i = 0; i < lbTables.Items.Count; i++)
                {
                    newSP.Clear();
                    newSP.setParams((string)lbTables.Items[i], test.getInfo((string)cmbDatabases.SelectedItem, (string)lbTables.Items[i]));
                    rtbMainEditor.AppendText(
                    "-- __________________________________________________" + "\n" +
                    "-- SP's for " + lbTables.Items[i] + " table" + "\n" +
                    "-- **************************************************" + "\n" );
                    if (cbSelect.Checked)
                        rtbMainEditor.AppendText(
                        newSP.SelectSP() + "\n" + "\n" );
                    if (cbInsert.Checked)
                        rtbMainEditor.AppendText(
                        newSP.InsertSP() + "\n" + "\n" );
                    if (cbDelete.Checked)
                        rtbMainEditor.AppendText(
                        newSP.DeleteSP() + "\n" + "\n" );
                    if (cbUpdate.Checked)
                        rtbMainEditor.AppendText(
                        newSP.UpdateSP() + "\n" + "\n");
                    
                    rtbMainEditor.AppendText(
                        "-- ***************************************************" + "\n");
                }

                laStatus.Text = "Finished! " + lbTables.Items.Count * 4 + " SP's Created!";
            } catch
            {
                laStatus.Text = "WHAT??????????";
            }
        }
		/// <summary>
		/// Generates the selected.
		/// </summary>
        private void GenerateSelected()
        {
            try
            {
                AppLib.MYSQLSET.DBTablesManage test = new PFDB.AppLib.MYSQLSET.DBTablesManage((string)cmbDatabases.SelectedItem, username, password, server);
                AppLib.MySQLSP newSP = new PFDB.AppLib.MySQLSP((string)lbTables.SelectedItem, test.getInfo((string)cmbDatabases.SelectedItem, (string)lbTables.SelectedItem));
                if (cbSelect.Checked)
                    rtbMainEditor.AppendText(newSP.SelectSP()+"\n");
                if (cbInsert.Checked)
                    rtbMainEditor.AppendText(newSP.InsertSP()+"\n");
                if (cbDelete.Checked)
                    rtbMainEditor.AppendText(newSP.DeleteSP()+"\n");
                if (cbUpdate.Checked)
                    rtbMainEditor.AppendText(newSP.UpdateSP()+"\n");
				if (cbSelectAll.Checked)
					rtbMainEditor.AppendText(newSP.SelectAllSP() + "\n");
            } catch (Exception)
            {

                laStatus.Text = "WHAT??????????";
            }
        }
		/// <summary>
		/// Generates all S p_ separate.
		/// </summary>
		private void GenerateAllSP_Separate()
		{
			try
			{
				AppLib.MYSQLSET.DBTablesManage test = new PFDB.AppLib.MYSQLSET.DBTablesManage((string)cmbDatabases.SelectedItem, username, password, server);
				AppLib.MySQLSP newSP = new PFDB.AppLib.MySQLSP();
				for (int i = 0; i < lbTables.Items.Count; i++)
				{
					newSP.Clear();
					newSP.setParams((string)lbTables.Items[i], test.getInfo((string)cmbDatabases.SelectedItem, (string)lbTables.Items[i]));
					for (int j = 0; j < 5; j++)
					{

						if (j == 0)
						{
							StreamWriter writer = new StreamWriter(SpPath + (string)lbTables.Items[i] + "Select.sql");
							writer.Write(
								newSP.SelectSP() + "\n" + "\n");
							writer.Close();
						}
						else if (j == 1)
						{
							StreamWriter writer = new StreamWriter(SpPath + (string)lbTables.Items[i] + "Insert.sql");
							writer.Write(
							newSP.InsertSP() + "\n" + "\n");
							writer.Close();
						}
						else if (j == 2)
						{
							StreamWriter writer = new StreamWriter(SpPath + (string)lbTables.Items[i] + "Delete.sql");
							writer.Write(
							newSP.DeleteSP() + "\n" + "\n");
							writer.Close();
						}
						else if (j == 3)
						{
							StreamWriter writer = new StreamWriter(SpPath + (string)lbTables.Items[i] + "Update.sql");
							writer.Write(
							newSP.UpdateSP() + "\n" + "\n");
							writer.Close();
						}
						else if (j == 4)
						{
							StreamWriter writer = new StreamWriter(SpPath + (string)lbTables.Items[i] + "SelectAll.sql");
							writer.Write(
							newSP.SelectAllSP() + "\n" + "\n");
							writer.Close();
						}
					}

				}

				laStatus.Text = "Finished! " + lbTables.Items.Count * 4 + " SP's Created!";
			} catch
			{
				laStatus.Text = "WHAT??????????";
			}
		}
		/// <summary>
		/// Retrieves all SP.
		/// </summary>
        private void RetrieveAllSP()
        {
            try
            {
                AppLib.MYSQLSET.DBTablesManage test = new PFDB.AppLib.MYSQLSET.DBTablesManage((string)cmbDatabases.SelectedItem, username, password, server);

                for (int i = 0; i < lbStoredProcedures.Items.Count; i++)
                {
                    rtbMainEditor.AppendText(
                            "-- ***********************************************************" + "\n" +
                            "-- " + (string)lbStoredProcedures.Items[i] + "\n" +
                            "DROP PROCEDURE IF EXISTS " + (string)lbStoredProcedures.Items[i] + ";\n" +
                            "CREATE PROCEDURE `" + (string)lbStoredProcedures.Items[i] + "`" +"(" + test.getSPParamList((string)cmbDatabases.SelectedItem, (string)lbStoredProcedures.Items[i], username, password, server) + ")\n" +
                             "\t" + "NOT DETERMINISTIC" + "\n" +
                             "\t" + "CONTAINS SQL" + "\n" +
                             "\t" + "SQL SECURITY INVOKER" + "\n" +
                             "\t" + "COMMENT \'\'" + "\n" +
                             test.getSPBody((string)cmbDatabases.SelectedItem, (string)lbStoredProcedures.Items[i], username, password, server) + ";\n" +
                            "-- ___________________________________________________________" + "\n"
                            );

                }
                laStatus.Text = "Finished! " + lbStoredProcedures.Items.Count + " SP's Merged!";

            } catch (Exception)
            {
                laStatus.Text = "WHAT??????????";
            }
        }
		/// <summary>
		/// Retrieves the selected.
		/// </summary>
        private void RetrieveSelected()
        {
            try
            {
                AppLib.MYSQLSET.DBTablesManage test = new PFDB.AppLib.MYSQLSET.DBTablesManage((string)cmbDatabases.SelectedItem, username, password, server);
                rtbMainEditor.AppendText(
                    "DROP PROCEDURE IF EXISTS " + (string)lbStoredProcedures.SelectedItem + ";\n" +
                    "CREATE PROCEDURE `" + (string)lbStoredProcedures.SelectedItem + "`" +
                    "(" + test.getSPParamList((string)cmbDatabases.SelectedItem, (string)lbStoredProcedures.SelectedItem, username, password, server) + ")\n" +
                    "\t" + "NOT DETERMINISTIC" + "\n" +
                    "\t" + "CONTAINS SQL" + "\n" +
                    "\t" + "SQL SECURITY INVOKER" + "\n" +
                    "\t" + "COMMENT \'\'" + "\n" +
                    test.getSPBody((string)cmbDatabases.SelectedItem, (string)lbStoredProcedures.SelectedItem, username, password, server) + ";\n\n"
                    );
                
            } catch (Exception)
            {
                laStatus.Text = "WHAT??????????";
            }
        }
		/// <summary>
		/// Retrieves all S p_ separate.
		/// </summary>
		private void RetrieveAllSP_Separate()
		{
			try
			{
				AppLib.MYSQLSET.DBTablesManage test = new PFDB.AppLib.MYSQLSET.DBTablesManage((string)cmbDatabases.SelectedItem, username, password, server);

				for (int i = 0; i < lbStoredProcedures.Items.Count; i++)
				{
					StreamWriter writer = new StreamWriter(SpPath + (string)lbStoredProcedures.Items[i] + ".sql");
					writer.Write(
						"DROP PROCEDURE IF EXISTS " + (string)lbStoredProcedures.Items[i] + ";\n" +
						"CREATE PROCEDURE `" + (string)lbStoredProcedures.Items[i] + "`" + "(" + test.getSPParamList((string)cmbDatabases.SelectedItem, (string)lbStoredProcedures.Items[i], username, password, server) + ")\n" +
						 "\t" + "NOT DETERMINISTIC" + "\n" +
						 "\t" + "CONTAINS SQL" + "\n" +
						 "\t" + "SQL SECURITY INVOKER" + "\n" +
						 "\t" + "COMMENT \'\'" + "\n" +
						 test.getSPBody((string)cmbDatabases.SelectedItem, (string)lbStoredProcedures.Items[i], username, password, server) + ";\n");
					writer.Close();
				}
				laStatus.Text = "Finished! " + lbStoredProcedures.Items.Count + " SP's Merged!";

			} catch (Exception)
			{
				laStatus.Text = "WHAT??????????";
			}
		}

		/// <summary>
		/// Handles the MouseMove event of the button6 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        private void button6_MouseMove(object sender, MouseEventArgs e)
        {
            button6.BackColor = Color.Blue;
            button6.Text = "SAVE";
            button6.ForeColor = Color.Yellow;
        }
		/// <summary>
		/// Handles the MouseLeave event of the button6 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button6_MouseLeave(object sender, EventArgs e)
        {
            button6.BackColor = Color.Black;
            button6.Text = "Save";
            button6.ForeColor = Color.White;
        }
		/// <summary>
		/// Handles the Click event of the button10 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void button10_Click(object sender, EventArgs e)
		{
			rtbMainEditor.ProcessAllLines();
		}

		/// <summary>
		/// Handles the Click event of the button11 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button11_Click(object sender, EventArgs e)
        {
            if (cmbDatabases.Items.Count!=0&&!cmbDatabases.SelectedItem.ToString().Equals(String.Empty))
            {
                rtbMainEditor.SelectAll();

				QueryRunner runner = new QueryRunner(cmbDatabases.SelectedItem.ToString(), rtbMainEditor.SelectedRtf, username, password, server);
                runner.Show();
            }
            else
            {
                MessageBox.Show("You Must Select a Database first!", "Querry Runner Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

		/// <summary>
		/// Handles the Click event of the button12 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void button12_Click(object sender, EventArgs e)
		{
			if (openFileDialog1.ShowDialog() == DialogResult.OK)
			{
				rtbMainEditor.Clear();
				Thread a = new Thread(thr);
				a.Start();
			}
		}

		/// <summary>
		/// Handles the Click event of the button13 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void button13_Click(object sender, EventArgs e)
		{
			if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
			{
				SpPath = folderBrowserDialog1.SelectedPath+"/";
				RetrieveAllSP_Separate();
			}
		}

		/// <summary>
		/// Handles the KeyPress event of the richTextBox1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.KeyPressEventArgs"/> instance containing the event data.</param>
        private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            
        }

		/// <summary>
		/// Handles the TextChanged event of the richTextBox1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            //if(richTextBox1.
            lbIntelisence.Items.Clear();
            foreach (object value in intel.GetList("se"))
            {
                lbIntelisence.Items.Add((string)value);
            }
            lbIntelisence.SelectedIndex = 0;
        }

		/// <summary>
		/// THRs this instance.
		/// </summary>
		public void thr()
		{
			StreamReader citac = new StreamReader(openFileDialog1.OpenFile());
			string linija;
			while ((linija = citac.ReadLine()) != null)
			{
				lock (rtbMainEditor)
				{
					rtbMainEditor.AppendText(linija);
					rtbMainEditor.AppendText("\n");
				}
				
			}
		}

		/// <summary>
		/// Handles the KeyDown event of the richTextBox1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param>
		private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.F8)
			{
				button10_Click(rtbMainEditor, new EventArgs());
			}
			if (e.KeyCode == Keys.F9)
			{
				button11_Click(rtbMainEditor, new EventArgs());
			}
		}

		/// <summary>
		/// Handles the KeyDown event of the listBox2 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param>
		private void listBox2_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
			{
				listBox2_MouseDoubleClick(sender, new MouseEventArgs(MouseButtons.Left,2,0,0,0));
			}
			if (e.KeyCode == Keys.Insert)
			{
				listBox2_MouseDown(sender, new MouseEventArgs(MouseButtons.Right, 1, 0, 0, 0));
			}
			if (e.KeyCode == Keys.F8)
			{
				button10_Click(rtbMainEditor, new EventArgs());
			}
			if (e.KeyCode == Keys.F9)
			{
				button11_Click(rtbMainEditor, new EventArgs());
			}
		}

		/// <summary>
		/// Handles the KeyDown event of the listBox1 control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param>
		private void listBox1_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
			{
				listBox1_DoubleClick(sender, new EventArgs());
			}
			if (e.KeyCode == Keys.Insert)
			{
				listBox1_MouseDown(sender, new MouseEventArgs(MouseButtons.Right, 1, 0, 0, 0));
			}
			if (e.KeyCode == Keys.F8)
			{
				button10_Click(rtbMainEditor, new EventArgs());
			}
			if (e.KeyCode == Keys.F9)
			{
				button11_Click(rtbMainEditor, new EventArgs());
			}

		}

		private void button14_Click(object sender, EventArgs e)
		{

		}

        //public void addKeyWords(string language)
        //{
        //    // Add the keywords to the list.
        //    FileStream read = new FileStream(language + ".lang", FileMode.Open, FileAccess.Read);
        //    StreamReader reader=new StreamReader(read);
        //    string linija;
        //    while (!reader.EndOfStream)
        //    {
        //        richTextBox1.Settings.Keywords.Add(reader.ReadLine().Trim());
        //    }
        //    // Set the comment identifier. For Lua this is two minus-signs after each other (--). 
        //    // For C++ we would set this property to "//".
        //    richTextBox1.Settings.Comment = "--";

        //    // Set the colors that will be used.
        //    richTextBox1.BackColor = Color.WhiteSmoke;
        //    richTextBox1.Settings.KeywordColor = Color.Blue;
        //    richTextBox1.Settings.CommentColor = Color.Green;
        //    richTextBox1.Settings.StringColor = Color.Gray;
        //    richTextBox1.Settings.IntegerColor = Color.Red;

        //    // Let's not process strings and integers.
        //    richTextBox1.Settings.EnableStrings = false;
        //    richTextBox1.Settings.EnableIntegers = false;

        //    // Let's make the settings we just set valid by compiling
        //    // the keywords to a regular expression.
        //    richTextBox1.CompileKeywords();

        //    // Load a file and update the syntax highlighting.
        //    richTextBox1.LoadFile(@"D:\WORK\Trening\PFDB\PFDB\test.txt", RichTextBoxStreamType.PlainText);
        //    richTextBox1.ProcessAllLines();
        //}
    }
}